home *** CD-ROM | disk | FTP | other *** search
Text File | 1999-06-26 | 4.6 KB | 302 lines | [TEXT/CWIE] |
- /*=============================*\
- Sound-IN-Sane
- A MacHack 1999 Production
-
- Developed and Written by
-
- Shawn Platkus
-
- June 25, 1999
- \*=============================*/
-
- // Filename: SIS_UI.c
-
- // This file handles the Event Loop and user interface stuff.
-
- #include "Sound-IN-Sane.h"
- #include "SIS_UI.h"
-
- // Globals
- Boolean gDone;
- Boolean gbInsanityOn = false;
- long gCycleTime = 60;
-
-
- //***
- // ToolboxInit
- //***
-
- void ToolboxInit (void)
- {
- InitGraf(&qd.thePort);
- InitFonts();
- InitWindows();
- InitMenus();
- TEInit();
- InitDialogs(NULL);
- InitCursor();
- }
-
-
- //***
- // MenuBarInit
- //***
-
- void MenuBarInit (void)
- {
- Handle menuBar;
- MenuHandle menu;
-
- menuBar = GetNewMBar(kMBARid);
- SetMenuBar(menuBar);
-
- menu = GetMenuHandle(mApple);
- AppendResMenu(menu, 'DRVR');
-
- DrawMenuBar();
- }
-
-
- //***
- // EventLoop
- //***
-
- void EventLoop (void)
- {
- EventRecord event;
- long startTicks = TickCount();
- long ticks = startTicks;
-
- gDone = ApplicationInit();
- while (gDone == false)
- {
- if (WaitNextEvent(everyEvent, &event, kSleep, NULL))
- DoEvent(&event);
-
- if (gbInsanityOn)
- {
- while ((TickCount() - ticks) > gCycleTime)
- {
- ticks = TickCount();
- CycleSoundSources();
- }
- }
-
- }
-
- ApplicationCleanUp();
- }
-
-
- //***
- // DoEvent
- //***
-
- void DoEvent (EventRecord *eventPtr)
- {
- char theChar;
-
- switch (eventPtr->what)
- {
- case mouseDown:
- HandleMouseDown(eventPtr);
- break;
- case keyDown:
- case autoKey:
- theChar = eventPtr->message & charCodeMask;
- if ((eventPtr->modifiers & cmdKey) != 0)
- HandleMenuChoice(MenuKey(theChar));
- break;
- }
- }
-
-
- //***
- // HandleMouseDown
- //***
-
- void HandleMouseDown (EventRecord *eventPtr)
- {
- WindowPtr window;
- short thePart;
- long menuChoice;
-
- thePart = FindWindow(eventPtr->where, &window);
-
- switch (thePart)
- {
- case inMenuBar:
- menuChoice = MenuSelect(eventPtr->where);
- HandleMenuChoice(menuChoice);
- break;
- case inSysWindow :
- SystemClick(eventPtr, window);
- break;
- }
- }
-
-
- //***
- // HandleMenuChoice
- //***
-
- void HandleMenuChoice (long menuChoice)
- {
- short menu;
- short item;
-
- if (menuChoice != 0)
- {
- menu = HiWord(menuChoice);
- item = LoWord(menuChoice);
-
- switch (menu)
- {
- case mApple:
- HandleAppleChoice(item);
- break;
- case mFile:
- HandleFileChoice(item);
- break;
- }
- HiliteMenu(0);
- }
- }
-
-
- //***
- // HandleAppleChoice
- //***
-
- void HandleAppleChoice (short item)
- {
- MenuHandle appleMenu;
- Str255 accName;
- short accNumber;
-
- switch (item)
- {
- case iAbout:
- SysBeep(20);
- break;
- default:
- appleMenu = GetMenuHandle(mApple);
- GetMenuItemText(appleMenu, item, accName);
- accNumber = OpenDeskAcc(accName);
- break;
- }
- }
-
-
- //***
- // HandleFileChoice
- //***
-
- void HandleFileChoice (short item)
- {
- switch (item)
- {
- case iDialog:
- DoDialog();
- break;
- case iQuit:
- gDone = true;
- break;
- }
- }
-
-
- //***
- // DoDialog
- //***
-
- void DoDialog(void)
- {
- ModalFilterUPP ModalFilter;
- DialogPtr dialog;
- Boolean dialogDone = false;
- short itemHit, iType;
- Handle iHandle;
- Rect iRect;
- Str255 cycleTimeStr;
- long number;
- int checkbox;
-
- dialog = GetNewDialog(kDialogResID, NULL, kMoveToFront);
-
- SetupDialog(dialog);
-
- ShowWindow(dialog);
- SetPort(dialog);
-
- /* These three routines are documented in
- Tech Note 304 (TB 37 in the new numbers).
- */
- SetDialogDefaultItem(dialog, kStdOkItemIndex);
- SetDialogTracksCursor(dialog, kEditItemExists);
-
- while (! dialogDone)
- {
- ModalDialog(NULL, &itemHit);
-
- switch(itemHit)
- {
- case ok:
- GetDialogItem(dialog, kItem_CycleTime, &iType, &iHandle, &iRect);
- GetDialogItemText(iHandle, cycleTimeStr);
- StringToNum( cycleTimeStr, &gCycleTime );
- //ProcessConfiguration(dialog);
- gbInsanityOn = true;
- dialogDone = true;
- break;
-
- default:
- if ((itemHit >= kItem_FirstCheckbox) && (itemHit <= kItem_LastCheckbox))
- {
- GetDialogItem(dialog, itemHit, &iType, &iHandle, &iRect);
- checkbox = GetControlValue((ControlHandle)iHandle);
- checkbox = 1 - checkbox;
- SetControlValue((ControlHandle)iHandle, checkbox);
- }
- }
- }
-
- DisposeDialog(dialog);
- DisposeRoutineDescriptor(ModalFilter);
-
- }
-
-
- //***
- // SetupDialog
- //***
-
- void SetupDialog(DialogPtr theDialog)
- {
- ModalFilterUPP ModalFilter;
- DialogPtr dialog;
- Boolean dialogDone = false;
- short itemHit, iType;
- Handle iHandle;
- Rect iRect;
- Str255 cycleTimeStr;
- long number;
- int checkbox;
-
- GetDialogItem(dialog, kItem_CycleTime, &iType, &iHandle, &iRect);
- NumToString(gCycleTime, cycleTimeStr);
- SetDialogItemText(iHandle, cycleTimeStr);
-
- return;
- }
-
-
- //***
- // HandleCheckbox
- //***
-
- void HandleCheckbox(DialogPtr theDialog, short itemHit)
- {
- int checkbox;
-
- }